<template>
    <!-- :model="facesigOperateInfo" -->
    <Card>
    <Row>
            <Row style="margin-left:35px;margin-top:30px;" >
                    <div v-if="videoTime !== null  ">
                        <p style="font-size:20px;">面谈时间提醒：距离面谈结束时间还剩:&nbsp; <strong style="color:red;font-size:35px;font-weight:bold;">{{videoTime}}</strong>&nbsp;</p>
                    </div>
                    <div v-if="passTime !== null">
                        <p style="font-size:20px;">面谈时间提醒：面谈结束时间已过:&nbsp; <strong style="color:red;font-size:35px;font-weight:bold;">{{passTime}}</strong>&nbsp;</p>
                    </div>
                    <Modal  v-model="modal2" title="自动退出提醒"   @on-cancel="cancel" >
                        <p>{{alertMessage}}</p>
                    </Modal>
                    <Form ref="from" :model="from" :rules="rules" >
                        <FormItem label="合同金额 :" prop="principalAmtAct">
                                <i-input type="text" style="width:150px;"  v-bind:readonly="isReadonly" :disabled="isReadonly"   v-model="from.principalAmtAct" placeholder="合同金额"></i-input>
                                <i-button v-if="modifyAmountBtn" type="primary" @click="updateContractMoney()" >{{updateMsg}}</i-button>
                        </FormItem>
                    </Form>
            </Row>
            <!-- v-if="sendCompactShow" -->
            <Row style="margin-left:35px;margin-top:30px;">
                <Card>
                    <i-button type="primary"  v-if="visaInterviewStartShow" @click="visaInterviewStart()">开始面签</i-button>

                    <i-button v-if="showContract" v-for="item in protocolTemplateList" :key="item" type="primary"   @click="showContractNow(item.templateNo)">{{item.templateName}}</i-button>

                    <!-- <i-button type="primary"        @click="sendLoanCompact('N')">发送货款合同</i-button> -->
                    <i-button v-if="restSendCompactShow" type="primary"       @click="downloadDetail()">重新发送贷款合同</i-button>
                    <i-button v-if="previewRepaymentShow" type="primary"        @click="PreviewRepaymentPlan()">预览还款计划</i-button>
                    <i-button v-if="resetCompactSignShow" type="primary"        @click="resetCompactSign()">重新发起协议签章</i-button>

                    <!-- <i-button type="primary"        @click="finishFaceSig()">完成视频面签</i-button> -->

                </Card>

                <Modal  v-model="modal6" title="退回原因"   @on-ok="SendContract('Y')">
                    <label>退回原因:</label>
                    <textarea  v-model="returnCause"  style="width:400px; height:40px;overflow-y:auto;" >
                    </textarea>
                </Modal>
            </Row>
            <Row>
                <Modal v-model="modal3" width="40%" :scrollable="true"  title="合同预览">
                    <Row v-html="serviceMsg"></Row>
                </Modal>
                <Modal v-model="RepaymentplanModal" width="40%" :scrollable="true"  title="还款计划">
                    <Row>
                         <Table :columns="RepaymentplanColumns" :data="dataPage"></Table>

                    </Row>
                </Modal>
            </Row>
            <!-- 视频面签状态1  2  4  5  6  8  9时显示 -->
            <Row v-if="interviewResultDiv" style="margin-left:35px;margin-top:20px;">
                <Col v-if="interviewResultDiv">
                    <span style="margin-top:30px;">
                        <strong style="color:#639df9;font-weight:bold;">|</strong> <strong>面谈结果</strong>
                    </span>
                    <Card>
                    <!-- interviewResultDiv:false,//面谈结果下拉框
                            nterviewResultTAB:false,//面谈结果多选框-->
                        <label>面谈结果:</label>
                        <Select v-model="lastInterviewResult" :disabled="interviewResultShow" style="width:200px"  label-in-value>
                            <Option v-for="item in interviewResults" :value="item.value" :key="item.value">{{ item.label }}</Option>
                        </Select>
                    </Card>
                </Col>
                <Col v-if="interviewResultTAB">
                   <Card>
                        <label>面谈记录:</label>
                        <textarea   v-model="lastInterviewRemark" :disabled="remarkOneShow" style="width:400px; height:40px;overflow-y:auto;" >
                        </textarea>
                    </Card>
                    <Card>
                        <CheckboxGroup v-model="interviewCheckboxOne">
                            <Checkbox label="01" :disabled="boxOne" v-model="initboxOne">
                                <span>身份信息已确认</span>
                            </Checkbox>
                            <Checkbox label="02" :disabled="boxTwo" v-model="initboxTwo">
                                <span>贷款金额、期限、费率、月还款额、还款日、收/还款账户已确认</span>
                            </Checkbox>
                            <Checkbox label="03" :disabled="boxThree" v-model="initboxThree">
                                <span>面谈无异常等待面签</span>
                            </Checkbox>
                        </CheckboxGroup>
                    </Card>
                </Col>
                <!-- v-if="interviewDisabled === true" -->
                 <Col>
                   <i-button  v-if="isShowInterviewSubmit" :disabled="interviewDisabled" type="primary" id="interviewSubmit" v-model="interviewSubmit" @click="interviewResultSubmit(true)" >提交</i-button>
                   <i-button  v-if="interviewHangShow" :disabled="interviewHangDisabled"  type="primary" id="interviewHang" v-model="interviewHang" @click="interviewResultSubmit(false)" >挂起</i-button>
                </Col>
            </Row>
               <!-- interviewSignDiv:false, //面签结果下拉框
                interviewSignTAB:false,//面签结果多选框 -->
            <Row v-if="interviewSignDiv" style="margin-left:35px;margin-top:20px;">
                <Col>
                    <span style="margin-top:30px;">
                        <strong style="color:#639df9;font-weight:bold;">|</strong> <strong>面签结果</strong>
                    </span>
                    <Card>
                    <label>面签结果:</label>
                    <Select v-model="lastVisaInterviewResult" :disabled="interviewSignResultShow" style="width:200px"  label-in-value>
                        <Option v-for="item in interviewSignResults" :value="item.value" :key="item.label">{{ item.label }}</Option>
                    </Select>
                    </Card>
                </Col>
                <Col v-if="interviewSignTAB">
                    <Card>
                    <label> 面签记录:</label>
                    <textarea   v-model="lastVisaInterviewRemark" :disabled="remarkTwoShow" style="width:400px; height:40px;overflow-y:auto;" >
                    </textarea>
                    </Card>
                    <Card>
                        <CheckboxGroup v-model="interviewCheckboxTwo">
                            <Checkbox label="01" :disabled="signChk1">
                                <span>审批额度在有限期内</span>
                            </Checkbox>
                            <Checkbox label="02" :disabled="signChk2">
                                <span>贷款金额、期限、费率、月还款额、还款日、收/还款账户已确认</span>
                            </Checkbox>
                            <Checkbox label="03" :disabled="signChk3">
                                <span>签字清晰且匹配一致</span>
                            </Checkbox>
                            <Checkbox label="04" :disabled="signChk4">
                                <span>面签无异常等待放款</span>
                            </Checkbox>
                        </CheckboxGroup>
                    </Card>
                </Col>
                <Col>
                   <i-button v-if="interviewSignSubmitShow" type="primary" v-model="interviewSignSubmit"  :disabled="interviewSignSubmitDisabled" @click="interviewSignResultSubmit($event)" >提交</i-button>
                </Col>
            </Row>
            </br>
            <Row>
                <span style="margin-left:35px;margin-top:30px;">
                    <strong style="color:#639df9;font-weight:bold;">|</strong> <strong>面签面谈记录</strong>
                </span>
                <Table style="margin-left:35px;margin-top:30px;"  :columns="columns1" :data="dataPage1"></Table>
            </Row>
             <!-- <div style="margin: 10px;overflow: hidden;float:right"></div> -->
             </Row>
        </Card>
</template>

<script>
export default {
  name: 'facesig-operate',
  data () {
    return {
      baseUrl: this.$appContext.marvels_core_approve,
      columns1: [{
        title: '序号',
        type: 'index',
        align: 'center'
      }, {
        title: '时间',
        key: 'createdDate',
        align: 'center',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.formatTime(params.row.createdDate))
          ])
        }
      }, {
        title: '操作',
        key: 'operationContent',
        align: 'center'
      },
      {
        title: '操作人员',
        key: 'updatedBy',
        align: 'center'
      }, {
        title: '备注',
        key: 'remark',
        align: 'center'
      }],
      RepaymentplanColumns: [{
        title: '期数',
        type: 'index',
        align: 'tenor'
      }, {
        title: '还款日期',
        key: 'paymentDate',
        align: 'center',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.formatTime(params.row.paymentDate))
          ])
        }
      }, {
        title: '最迟还款日期',
        key: 'paymentDateLate',
        align: 'center',
        width: 160,
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.formatTime(params.row.paymentDateLate))
          ])
        }
      }, {
        title: '本金',
        key: 'principal',
        align: 'center'
      },
      {
        title: '利息',
        key: 'interest',
        align: 'center'
      }, {
        title: '金额',
        key: 'amount',
        align: 'center',
        render: (h, params) => {
          return h('div', [
            h('span', (params.row.principal + params.row.interest).toFixed(2))
          ])
        }

      }],
      type: null,
      dataPage: [],
      dataPage1: [],
      videoTime: null,
      startTime: null,
      endtime: null,
      passTime: null, // 已过面谈时间
      rangeTime: null, // 面签时间
      appointmentDate: null, // 预约时间
      principalAmtAct: null, // 合同金额
      tempPrincipalAmtAct: null,
      isReadonly: true, // 默认金额只读
      remark: null, // 面谈记录
      updateMsg: '调整金额', // 默认按钮值
      count: 0, // 记录点击次数
      stateCount: 0, // 记录提示信息
      modal2: false, // 面签时间过期提示
      modal3: false, // 合同模版
      modal6: false, // 退出原因按钮
      returnCause: null, // 退回原因
      visaInterviewStartShow: true, // 开始面签按钮
      resetCompactSignShow: false, // 重新发起协议签章
      previewRepaymentShow: true, // 预览还款计划
      RepaymentplanModal: false, // 还款计划
      isvidepModel: false,
      alertMessage: null,
      serviceMsg: null,
      haveInterview: 'N',
      model4: null,
      model5: null,
      appAmount: null,
      minAmonut: '',
      lastInterviewResult: '', // 面谈结果
      lastInterviewRemark: '',
      lastVisaInterviewResult: '', // 面签
      lastVisaInterviewRemark: '',
      isShowInterviewSubmit: true,
      isShowVisaSubmit: true,
      interviewSignResults: [
        { value: '', label: '请选择' },
        { value: '01', label: '通过' },
        { value: '02', label: '否决' }
      ],
      interviewResults: [
        { value: '', label: '请选择' },
        { value: '01', label: '通过' },
        { value: '02', label: '否决' },
        { value: '03', label: '退回' }
      ],
      interviewResult: null,
      interviewSignResult: null,
      remarkOne: null,
      remarkTwo: null,
      interviewCheckboxOne: [

      ],
      interviewCheckboxTwo: [],
      interviewSignSubmit: null,
      interviewSubmit: null,
      interviewHang: null,
      interviewHangShow: true,
      interviewDisabled: false,
      interviewHangDisabled: false,
      remarkOneShow: false,
      interviewResultShow: false,
      boxOne: false,
      boxTwo: false,
      boxThree: false,
      initboxOne: null,
      initboxTwo: null,
      initboxThree: null,
      interviewResultDiv: false, // 面谈结果下拉框
      interviewResultTAB: false, // 面结果多选框
      interviewSignDiv: false, // 面签结果下拉框
      interviewSignTAB: false, // 面签结果多选框
      interviewSignSubmitShow: false, // 面签提交按钮
      sendCompactShow: false, // 发送贷款合同
      showContract: true, // 合同预览
      restSendCompactShow: false, // 重新发送贷款合同按钮
      interviewSignSubmitDisabled: false,
      signChk1: false,
      signChk2: false,
      signChk3: false,
      signChk4: false,
      interviewSignResultShow: false,
      remarkTwoShow: false,
      modifyAmountBtn: true, // 调整金额
      remindTimeType: 'm', // 面谈倒计时
      haveBackground: 1,
      remindInterviewReturn: 'N',
      startDateTime: null,
      endDateTime: null,
      exitQueryInterviewCancel: 'N',
      waitTime: null,
      from: {
        principalAmtAct: null
      },
      rules: {
        principalAmtAct: [
          { required: true, message: '金额不能为空', trigger: 'blur' },
          { pattern: this.$util.regExpAmount, message: '修改金额必须为数字!', trigger: 'blur' }
        ]
      },
      protocolTemplateList: [],
      rejectReason: null
    }
  },
  methods: {
    // 初始化金额
    getAppAmount: function () {
      var vm = this
      var loanId = vm.$route.query.loanId
      vm.type = vm.$route.query.type
      // 合同金额
      this.$ajax.get(vm.baseUrl + 'approve/video/service/getAppAmount/' + loanId + '/' + this.$route.query.id).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          vm.$Message.warning(message)
          return
        }
        vm.appAmount = data.data.appAmount// 核定金额
        vm.minAmonut = data.data.minAmonut// 最低金额
        vm.from.principalAmtAct = data.data.appAmount === '.00' ? '0.00' : data.data.appAmount // 申请金额
        vm.tempPrincipalAmtAct = data.data.appAmount === '.00' ? '0.00' : data.data.appAmount
        vm.protocolTemplateList = data.data.protocolTemplateList// 合同模板列表
        vm.dataPage1 = data.data.facesigOperates || []/// /面签记录
        if (data.data.faceSigAppointmentDto) {
          vm.startDateTime = this.getNowFormatDate(data.data.faceSigAppointmentDto.appointmentDate) + ' ' + this.getHourMinuteSeconds(data.data.faceSigAppointmentDto.startTime)// 面签开始时间
          vm.endDateTime = this.getNowFormatDate(data.data.faceSigAppointmentDto.appointmentDate) + ' ' + this.getHourMinuteSeconds(data.data.faceSigAppointmentDto.endTime)// 面签结束时间
          vm.type = Number(data.data.faceSigAppointmentDto.faceSigStatus)
        }
        vm.waitTime = data.data.waitTime// 等待时间
        // 遍历所有查询到的面谈/面签内容
        vm.dataPage1.forEach(item => {
          if (item.resultType === '01') { // 面谈
            // 面谈类型数据
            vm.lastInterviewRemark = item.remark
            vm.lastInterviewResult = item.result
          }
          if (item.resultType === '02') { // 面签
            // 面签类型数据
            vm.lastVisaInterviewRemark = item.remark
            vm.lastVisaInterviewResult = item.result
          }
        })
        vm.resetVisaInterviewStartHide()
        // 按钮控制
        vm.resetInterviewStatus()
        vm.resetVisaInterviewStatus()
      }).catch(er => {

      })
    },
    getNowFormatDate (time) {
      var date = new Date(time)
      var seperator1 = '-'
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var strDate = date.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate
      return currentdate
    },
    getHourMinuteSeconds (time) {
      var date = new Date(time)
      var seperator1 = ':'
      var hour = date.getHours()
      var minute = date.getMinutes()
      var seconds = date.getSeconds()
      if (hour >= 1 && hour <= 9) {
        hour = '0' + hour
      }
      if (minute >= 0 && minute <= 9) {
        minute = '0' + minute
      }
      if (seconds >= 0 && seconds <= 9) {
        seconds = '0' + seconds
      }
      var currentdate = hour + seperator1 + minute + seperator1 + seconds
      return currentdate
    },
    // 设置面谈元素状态
    resetInterviewStatus () {
      if (this.lastInterviewResult === '03') { // 面谈结果（面谈退回）
        this.lastInterviewResult = ''
      }
      this.remarkOne = this.lastInterviewRemark
      // 面签不为挂起(10)且面谈结果为通过或者不通过
      // 或者面签状态为已过号（3）或者面谈退回（5） 所有元素不可操作
      if ((this.type !== 10 && this.lastInterviewResult === '01') || (this.type !== 10 && this.lastInterviewResult === '02') || this.type === 3 || this.type === 5) {
        // 下拉框不可用
        this.interviewResultShow = true
        if (this.lastInterviewResult === '01') { // 面谈通过
          this.interviewCheckboxOne = ['01', '02', '03']
        }
        // 三个选项不可选
        this.boxOne = true
        this.boxTwo = true
        this.boxThree = true
        this.remarkOneShow = true
        // 挂起按钮隐藏
        this.interviewHangDisabled = false
        this.interviewHangShow = false
        // 显示重签协议签章
        this.resetCompactSignShow = true
        // 提交按钮隐藏
        this.isShowInterviewSubmit = false
        // 面谈为非通过或者面签结果不为空
        if (this.lastInterviewResult !== '01' || this.lastVisaInterviewResult !== '') {
          this.modifyAmountBtn = false// 隐藏调整金额按钮
          this.sendCompactShow = false// 隐藏贷款合同按钮
        }
      }
      // 非待面谈且不为已过号显示面谈记录和面谈结果
      if (this.type !== 0 && this.type !== 3) {
        this.interviewResultDiv = true
        this.interviewResultTAB = true
      }
    },
    // 设置面签元素状态
    resetVisaInterviewStatus () {
      this.remarkTwo = this.lastVisaInterviewRemark
      // 面签结果为通过时设置面签元素不可用 3--已过号
      if (this.lastVisaInterviewResult === '01' || this.lastVisaInterviewResult === '02' || this.type === 3) {
        this.interviewSignSubmitDisabled = true
        this.isShowVisaSubmit = false
        this.interviewSignSubmitShow = false// 提交
        this.modifyAmountBtn = false// 调整金额按钮
        // this.sendCompactShow=false;//发送贷款合同
        this.showContract = true// 合同预览
        this.previewRepaymentShow = false// 预览还款计划
        this.restSendCompactShow = false// 重新发送贷款合同
        this.resetCompactSignShow = true// 重新发起协议签章
        if (this.lastVisaInterviewResult === '01') {
          this.interviewCheckboxTwo = ['01', '02', '03', '04']
        }
        this.interviewSignResultShow = true
        this.signChk1 = true
        this.signChk2 = true
        this.signChk3 = true
        this.signChk4 = true
        this.remarkTwoShow = true
      }
      if (this.lastVisaInterviewResult !== '' || (this.type !== 10 && this.lastInterviewResult === '01')) {
        this.interviewSignDiv = true
        this.interviewSignTAB = true
        this.interviewSignSubmitShow = true
      }
      if (this.type === 10 || this.lastInterviewResult !== '01' || this.lastVisaInterviewResult === '01' || this.lastVisaInterviewResult === '02') {
        this.interviewSignSubmitShow = false
      } else {
        this.interviewSignSubmitShow = true
      }
    },
    updateContractMoney: function () {
      this.updateMsg = '保存金额'
      this.isReadonly = false
      if (this.count > 0) {
        var vm = this
        this.$refs.from.validate(valid => {
          if (valid) {
            var config = { title: '提示' }
            config.content = '是否确认调整?'
            config.onOk = vm.updateData
            vm.$Modal.confirm(config)
            this.updateMsg = '保存金额'
            this.isReadonly = false
          }
        })
      }
      this.count = 1
      this.isReadonly = false
    },
    updateData: function () { // 修改合同金额
      this.updateMsg = '调整金额'
      this.isReadonly = true
      var modifyAmount = this.from.principalAmtAct
      if (this.appAmount < parseFloat(modifyAmount, 10)) {
        this.from.principalAmtAct = this.tempPrincipalAmtAct
        this.$Message.warning('修改金额必须小于修改前核准金额！')
        return
      }
      if (parseFloat(modifyAmount, 10) < this.minAmonut) {
        this.from.principalAmtAct = this.tempPrincipalAmtAct
        this.$Message.warning('修改金额必需大于最小申请金额！')
        return
      }
      if (parseFloat(this.from.principalAmtAct) <= 0) {
        this.$Message.warning('修改金额必需是大于0的数字!')
        return
      }
      // 调整合同金额
      var params = {
        'loanId': this.$route.query.loanId,
        'amount': this.from.principalAmtAct,
        'appointmentId': this.$route.query.id,
        'resultType': '03',
        'result': '01'
      }
      this.updateAmount(params)
    },
    // 修改面签数据
    updateAmount: function (paramsData) {
      this.$ajax.post(this.baseUrl + 'approve/video/service/modifyCompactAmount', paramsData).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
        } else {
          // 刷新页面
          this.getAppAmount()
          this.count = 0
        }
      }).catch(er => {

      })
    },
    // 获取面签时间  0未面签,1正在面签,2已面签,(面签通过)3已过号,4面谈通过,5面谈退回,6面谈拒绝,7待面签,8面签退回,9面签拒绝
    getRangeTime: function () {
      var vm = this
      var outTime = this.getTimeDiff(vm.startDateTime, 'm')
      if ((vm.type !== 1 && vm.type !== 10) || vm.haveInterview === 'Y') {
        return
      }
      // 获取房间记录
      this.$ajax.get(this.baseUrl + 'approve/roomlog/service/getRoomLog/' + Number(this.$route.query.id)).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        var roomlogs = data.data || []
        roomlogs.forEach(item => {
          // 1客户经理,2客户,3助理
          if (item.userType === 1 || item.userType === 2 || item.userType === 3) {
            vm.haveInterview = 'Y'
          }
        })
        if (vm.haveInterview === 'N' && outTime > parseInt(vm.waitTime, 10)) {
          var paramsData = {
            'id': this.$route.query.id,
            'loanId': this.$route.query.loanId,
            'faceSigStatus': '3'
          }
          this.$ajax.post(this.baseUrl + 'approve/video/service/modifyInterviewSignStatus', paramsData).then(re => {
            var data = re.data
            var code = data.code
            if (code !== 'success') {
              this.alertMessage = '预约开始面谈时间已过(' + outTime + ')分钟且客户未进入房间开始视频，系统已自动将预约更新为已过号。您可以退出面签'
              this.type = 3
            } else {
              this.alertMessage = '预约开始面谈时间已过(' + outTime + ')分钟且客户未进入房间开始视频，系统已自动将预约更新为已过号。您可以退出面签'
              this.type = 3
            }
            this.resetInterviewStatus()
            this.resetVisaInterviewStatus()
          }).catch(er => {
            this.alertMessage = '预约开始面谈时间已过(' + outTime + ')分钟且客户未进入房间开始视频，系统已自动将预约更新为已过号。您可以退出面签'
            this.type = 3
            this.resetInterviewStatus()
            this.resetVisaInterviewStatus()
          })
          if (this.stateCount === 0) {
            this.modal2 = true // 弹出提示已过号
            this.stateCount = 1
          }
        }
      }).catch(er => {

      })
    },
    cancel () {
      // this.$Message.info('Clicked cancel');
    },
    // 开始面签
    visaInterviewStart () {
      var paramsData = {
        'id': this.$route.query.id, // 面签编号
        'userId': this.$route.query.userId // 用户编号
      }
      this.$ajax.post(this.baseUrl + 'approve/video/service/pushFaceSig', paramsData).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
        } else {
          this.$Message.success({
            content: '已开始面谈，请通过IPAD进入房间开始面谈！',
            duration: 4
          })
          // 面漆状态变为1，开始面签按钮不显示
          this.type = 1
          this.visaInterviewStartShow = false
          if (this.type !== 0 && this.type !== 3) {
            this.interviewResultDiv = true
            this.interviewResultTAB = true
          }
        }
      }).catch(er => {

      })
    },

    /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    showContractNow (templateNo) { // 预览合同
      var loanId = this.$route.query.loanId
      this.$ajax.get(this.baseUrl + 'approve/video/service/showContract/' + loanId + '/' + '1').then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        this.modal3 = true // 合同模版
        this.serviceMsg = data.data.htmlData
      }).catch(er => {

      })
    },
    downloadDetail () { // 重新发送电子合同
      this.returnCause = null
      this.modal6 = true
    },
    SendContract (isResend) {
      this.sendLoanCompact(isResend)
    },
    sendLoanCompact (isResend) { // 发送合同服务
      var loanId = this.$route.query.loanId
      var appointmentId = this.$route.query.id
      // this.count = 0;
      var params = { 'loanId': loanId, 'appointmentId': appointmentId, 'isResend': isResend }
      var returnCause = this.returnCause
      if (returnCause === '' || returnCause === null) {
        this.$Message.warning('未输入退回原因，不能提交！')
        return
      }
      if (returnCause.length > 256) {
        this.$Message.warning('退回原因输入过长，不能提交！')
        return
      }
      params.returnCause = returnCause
      this.$ajax.post(this.baseUrl + 'approve/video/service/SendContract', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
        }
      }).catch(er => {

      })
    },
    // 预览还款计划
    PreviewRepaymentPlan () {
      this.$ajax.get(this.baseUrl + 'approve/video/service/previewRepaymentPlan/' + this.$route.query.loanId).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        this.RepaymentplanModal = true
        if (data.data.loanTrailDTO) {
          this.dataPage = data.data.loanTrailDTO.planInfo || []
        }
      }).catch(er => {

      })
    },
    // 重签电子合同
    resetCompactSign () {
      var loanId = this.$route.query.loanId
      var appointmentId = this.$route.query.id
      var params = { 'loanId': loanId, 'appointmentId': appointmentId }
      this.$ajax.post(this.baseUrl + 'approve/video/service/resetCompactSign', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        this.$Message.success('重新发送电子合同成功！')
      }).catch(er => {

      })
    },
    /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // 提交面谈结果
    interviewResultSubmit (event) {
      var interviewStuts = this.lastInterviewResult
      if (this.lastInterviewResult === null) {
        this.$Message.warning('面谈结果不能为空')
        return
      }
      var remark = this.lastInterviewRemark
      if (interviewStuts === '03') {
        if (remark === '') {
          this.$Message.warning('未输入面谈记录，不能提交!')
          return
        }
        if (remark.length > 256) {
          this.$Message.warning('面谈记录输入过长，不能提交!')
          return
        }
      }
      // 添加type判断是否为挂起
      var type
      if (event) {
        type = true
      } else {
        type = false
      }
      if (interviewStuts === '') {
        this.$Message.warning('未选择面谈结果，不能提交')
        return
      }
      if (this.haveInterview === 'N' && interviewStuts === '01' && type) {
        this.$Message.warning('客户还未进入房间进行面签，不能提交面谈结果为通过！')
        return
      }
      if (this.haveInterview === 'N' && !type) {
        this.$Message.warning('客户还未进入房间面谈，不能挂起')
        return
      }

      // 如果为提交,则隐藏
      if (type) { // 添加挂起按钮隐藏
        this.interviewDisabled = true
        this.interviewHangShow = false
        this.interviewHangDisabled = true
      }
      remark = this.lastInterviewRemark//
      if (interviewStuts === '01' && type) {
        var interviewCheckboxOne = this.interviewCheckboxOne
        if (interviewCheckboxOne.length < 3) {
          // 添加挂起按钮解除隐藏
          this.interviewDisabled = false
          this.interviewHangShow = true
          this.interviewHangDisabled = false
          this.$Message.warning('面谈结果选择通过时，问题项必选全部勾选！')
          return
        }
      }
      if (type) {
        this.interviewResultShow = true
        this.boxOne = false
        this.boxTwo = false
        this.boxThree = false
        this.remarkOneShow = true
      }
      var operationContent = '面谈' + interviewStuts
      if (!type) {
        operationContent = '挂起操作'
      }
      var params = {
        loanId: this.$route.query.loanId,
        caseId: this.$route.query.userId,
        result: interviewStuts,
        remark: remark,
        operationContent: operationContent,
        type: type,
        appointmentId: this.$route.query.id,
        resultType: '01' }
      this.$ajax.post(this.baseUrl + 'approve/video/service/addInterviewResult', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        if (data.data === 1 && type) {
          if (this.type === 10) {
            this.type = ''
          }
          this.getAppAmount()
          if (resultCode === '01') {
            this.interviewSignDiv = true// 面签结果下拉框
            this.interviewSignTAB = true// 面签结果多选框
            this.type = 4
          } else if (resultCode === '02') {
            this.type = 6
          } else if (resultCode === '03') {
            this.type = 5
          }
          this.$Message.success('提交面谈结果成功！')
          this.interviewHangShow = false
          this.restSendCompactShow = true
        } else if (obj.result.resultCode === '00' && !type) {
          this.type = 10
          this.getAppAmount()
          this.interviewHangShow = false
          this.$Message.success('挂起面谈结果成功！')
        } else {
          if (type) {
            this.$Message.warning('提交失败' + message)
          } else {
            this.$Message.warning(message)
          }
          // 添加挂起按钮解除隐藏
          this.interviewDisabled = false
          this.interviewHangShow = true
          this.interviewHangDisabled = false
          this.remarkOneShow = true
        }
      }).catch(er => {

      })
    },
    // 提交面签结果
    interviewSignResultSubmit () {
      var resultCode = this.lastVisaInterviewResult
      if (resultCode === '') {
        this.$Message.warning('未选择面签结果，不能提交！')
        return
      }
      var selectedText = this.interviewCheckboxTwo
      var remark = this.lastVisaInterviewRemark
      if (resultCode === '01') {
        if (selectedText.length < 4) {
          this.$Message.warning('面签结果选择通过时，问题项必选全部勾选！')
          this.interviewSignSubmitShow = true// 显示提交按钮
          this.interviewSignSubmitDisabled = false
          return
        }
      }
      if (resultCode !== '03') {
        this.interviewSignSubmitShow = true// 显示提交按钮
        this.interviewSignSubmitDisabled = false
        this.interviewResultShow = true
        this.signChk1 = true
        this.signChk2 = true
        this.signChk3 = true
        this.signChk4 = true
      }
      var operationContent = '面签' + selectedText
      var params = {
        loanId: this.$route.query.loanId,
        caseId: this.$route.query.userId,
        result: resultCode,
        remark: remark,
        operationContent: operationContent,
        resultType: '02',
        type: true,
        appointmentId: this.$route.query.id
      }
      this.$ajax.post(this.baseUrl + 'approve/video/service/addInterviewResult', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(data.data)
          return
        }
        if (data.data === 1) {
          this.getAppAmount()
          var messagedata = '提交面签结果成功'
          if (resultCode === '01') {
            this.interviewSignDiv = true
            this.interviewSignTAB = true
            this.interviewSignSubmitShow = false
            this.modifyAmountBtn = false
            this.type = 2
          } else if (resultCode === '02') {
            this.type = 9
          }
          this.$Message.success(messagedata + '!')
        } else {
          this.interviewSignResultShow = true// 面谈结果
          this.signChk1 = true
          this.signChk2 = true
          this.signChk3 = true
          this.signChk4 = true
          this.remarkTwoShow = true
          this.interviewSignSubmitShow = true// 显示提交按钮
          this.interviewSignSubmitDisabled = false
          this.$Message.warning(message)
        }
      }).catch(er => {

      })
    },
    // 面谈倒计时
    remindInterviewTime () {
      // 如果当前时间大于面签开始时间，则显示面谈时间提醒,否则返回
      var timeDiff = this.getTimeDiff(this.startDateTime, 's')
      if (timeDiff < 0 || this.remindInterviewReturn === 'Y' || this.type !== 1) {
        return
      }
      var outTime = this.getTimeDiff(this.endDateTime, this.remindTimeType)
      if (outTime > 0) {
        this.passTime = outTime + '分钟'
        this.remindInterviewReturn = 'Y'
        return
      }
      // 距离面谈结束时间不足一分钟时，系统改为按秒提醒 color:red;
      if (this.remindTimeType === 's' || (this.remindTimeType === 'm' && outTime >= -2)) {
        this.remindTimeType = 's'
        outTime = getTimeDiff(endDateTime, 's')
        if (this.haveBackground === 1) {
          this.haveBackground = 0
          this.videoTime = outTime + ' 秒'
        } else {
          this.haveBackground = 1
          this.videoTime = outTime
        }
        if (outTime === -40) {
          this.videoTime = -outTime + ' 秒，请您把握好时间尽快完成面谈！'
        } else if (outTime === -20) {
          this.videoTime = -outTime + ' 秒，请您把握好时间尽快完成面谈！'
        }
      } else if (this.remindTimeType === 'm' && outTime < -2) {
        this.videoTime = -outTime + ' 分钟，请您把握好时间尽快完成面谈！'
      }
    },
    // 查询此面签是否已经取消预约，如果已经取消预约提醒面签人员
    // 如果已经开始面签则不在进行查询
    isInterviewCancel () {
      // 判断是否还需要继续查询是否已经取消面签,如果已取消面签或已进入房间开始面签则无需在查询状态
      if (this.exitQueryInterviewCancel === 'Y' || this.haveInterview === 'Y') {
        return
      }
      var appointmentId = this.$route.query.id
      if (!appointmentId || (appointmentId !== null && appointmentId !== '')) return
      var url = this.baseUrl + 'approve/spmq/service/queryCancelStatus/' + appointmentId
      this.$ajax.get(url).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
        } else if (data.data.cancel === 0) { // 清空当前面谈/面签内容列表
          this.exitQueryInterviewCancel = 'Y'
          this.$Message.success('客户已经取消面签，您可以退出此面签任务！')
        } else if (data.data.faceSigStatus === 1) { // 状态变为面谈中
          this.type = data.data.faceSigStatus
          this.resetInterviewStatus()
        }
      }).catch(er => {

      })
    },
    resetVisaInterviewStartHide () {
      if (this.type === 0) {
        this.visaInterviewStartShow = true
      } else {
        this.visaInterviewStartShow = false
      }
    },
    // 计算时间
    getTimeDiff (dateStr, diffType) {
      if (dateStr && dateStr !== null && dateStr !== '') {
        dateStr = dateStr + ''
        dateStr = dateStr.replace(/-/g, '/')
        var date = new Date(Date.parse(dateStr))
        var currentDate = new Date()
        var diffSeconds = currentDate.getTime() - date.getTime()
        if (diffType === 'm') {
          return parseInt(diffSeconds / 1000 / 60)
        } else if (diffType === 's') {
          return parseInt(diffSeconds / 1000)
        }
      }
    }
  }, // end method
  created () {
    this.$ajax = this.$util.ajax(this.$appContext.marvels_core_approve)
  },
  mounted () {
    // 初始化金额
    // this.getAppAmouunt()
    // 查询面谈/面签数据记录
    // this.searchInterviewResult();
    setInterval(this.getRangeTime, 300)
    // 如果正在面签中，则刷新时间提醒
    setInterval(this.remindInterviewTime, 300)
    // 控制开始面签按钮
    setTimeout(this.resetVisaInterviewStartHide, 1000)
    // 轮询客户经理是否已取消面签
    setInterval(this.isInterviewCancel, 1000 * 60)
  },
  // 初始化
  computed: {
    loanId () {
      return parseInt(this.$route.query.loanId)
    },
    userId () {
      return parseInt(this.$route.query.userId)
    },
    id () {
      return parseInt(this.$route.query.id)
    }
  },
  watch: {
    // 点击tab页签，加载数据，只加载一次
    'taskParams.facesigOperateInfo' (v) {
      if (v) {
        // if(this.$route.query.type !== '10'){
        this.resetVisaInterviewStartHide()
        // }
        // 初始化金额
        this.getAppAmount()
        // 查询面谈/面签数据记录
        // this.searchInterviewResult();
      }
    }
  },
  props: {
    taskParams: Object
  }
}
</script>
